define(['config/appregister',"business/vedio/services/httpServices","business/personalcenter/service/shoppingHttp","jquery","business/services/detailNavComp"],function(app,httpService,shoppingHttp){
    app.controller('payNowCtrl',function($scope,$state,$stateParams,$q){
        //立即支付
        var formEle=document.getElementById('payForm');
        formEle.action='http://'+allUrl+':8080/elink_user/api/pay/submitPay';
        //formEle.action='http://192.168.0.31:8080/elink_user/api/pay/submitPay';
        $scope.pay=function(){
            formEle.submit();
        };

        function getLocalStorage(){
            if(localStorage.getItem('orderInfo')){
                $scope.dataList=JSON.parse(localStorage.getItem('orderInfo'));
                console.log($scope.dataList);
                $scope.price=0;
                angular.forEach($scope.dataList, function(data,index){
                    angular.forEach(data.cartList, function(info,i){
                        if(info.scId){
                            $scope.price+=info.money;
                        }
                    });
                });
            }
        }


        //获取支付课程信息 orderType为2是购买下单 为1是报名下单
        if($stateParams.orderType==2){
            getLocalStorage();
            confirmOrder();
        }else{
            getPayInfo($stateParams.courseId);
            confirmOrder();
        }
        function getPayInfo(item){
            var req ={
                type:"GET",
                uri:"get?courseId=" + item,
                data:{}
            };
            httpService.getcourse(req).success(function(data){
                $scope.$apply(function(){
                    $scope.courseInfo=data.data.course;
                    $scope.price=$scope.courseInfo.price;
                    return $scope.courseInfo;
                })
            }).error(function(){
                console.log('获取支付课程信息失败');
            })
        }

        function confirmOrder(){
            var req ={
                type:"GET",
                uri:"confirmOrder",
                data:{
                    payIds:$stateParams.payId,
                    courseIds:$stateParams.courseId

                }
            };
            shoppingHttp.getOrderInfo(req).success(function(data){
                $scope.$apply(function(){
                    $scope.orderInfo=data;
                })
            }).error(function(){
                console.log('获取支付课程信息失败');
            })
        }

        $scope.detail = false;
        $scope.ali = true;
        $scope.weChat = false;
        $scope.aliPay = function(){
            if(!$scope.ali){
                $scope.ali = !$scope.ali;
                $scope.weChat = !$scope.weChat;
            }
        }
        $scope.chatPay = function(){
            if(!$scope.weChat){
                $scope.weChat = !$scope.weChat;
                $scope.ali = !$scope.ali;
            }
        }
        $scope.payDetail = function(){
            $scope.detail = !$scope.detail;
        }
        $scope.goPay = function(){
            $state.go('chatPayCtrl')
        }


     /*   $scope.pay = function(){
            $.ajax({
                type:'POST',
                url:'http://192.168.0.31:8080/elink_user/api/pay/submitPay',
                data:{
                    WIDout_trade_no:11111111111111111,
                    WIDsubject:2222222,
                    WIDtotal_fee:0.01,
                    WIDbody:'哈哈哈'
                }
            }).success(function(data){
                //window.open(data)
            })
        }*/

    })
})/**
 * Created by white on 2017/2/27.
 */
